package com.zhanghe.study.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 测试生命周期
 * 1、加载 classLoader
 * 2、实例化
 * 3、init(ServletConfig) ServletConfig保存着对于Servlet的配置信息
 * 4、处理请求 doGet/doPost
 * 5、销毁 destroy
 */
public class LifeCycleServlet extends HttpServlet {
    //  构造器先走
    public LifeCycleServlet(){
        System.out.println("构造器");
    }

    // 第二步初始化 只会初始化一次 一直使用该Servlet实例
    @Override
    public void init() throws ServletException {
        System.out.println("init");
    }

    // 处理请求doGet
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("doGet");
    }

    @Override
    public void destroy() {
        System.out.println("destroy");
    }
}
